package com.may.rabbitmq.two;

import com.may.rabbitmq.utils.RabbitMqUtils;
import com.rabbitmq.client.CancelCallback;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * Created with IntelliJ IDEA.
 *
 * @author nakano_may丶
 * @date 2023/4/9
 * @Version 1.0
 * @description 这是一个工作线程（相当于之前的消费者）
 */
public class Worker01 {
    /**
     * 队列名称
     */
    public static final String QUEUE_NAME = "hello";

    // 接收消息
    public static void main(String[] args) throws IOException, TimeoutException {
        Channel channel = RabbitMqUtils.getChannel();

        // 消息的接收
        DeliverCallback deliverCallback = (consumerTag, message) -> {
            System.out.println("接收到的消息：" + new String(message.getBody()));
        };

        // 消息接收被取消时回调
        CancelCallback cancelCallback = (consumerTag) -> {
            System.out.println(consumerTag + "消息取消消费者的回调逻辑！");
        };
        System.out.println("c2等待接收消息......");
        channel.basicConsume(QUEUE_NAME,true, deliverCallback, cancelCallback);
    }
}
